package com.example.sprintboot.service;

import com.example.sprintboot.entity.Category;
import com.example.sprintboot.mapper.CategoryMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    public List<Category> selectAll() {
        return categoryMapper.selectAll(); // 调用 EmployeeMapper 的方法
    }


    public Category selectById(Integer id) {
        return  categoryMapper.selectById(id);
    }

    public void add(Category category) {
        categoryMapper.add(category);
    }

    public void update(Category category) {
        categoryMapper.update(category);
    }

    public void delete(Integer id) {
        categoryMapper.delete(id);
    }

    public PageInfo<Category> page(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Category> list =  categoryMapper.selectAll();
        return PageInfo.of(list);
    }

    public PageInfo<Category> query(String name, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Category> list = categoryMapper.query(name);
        return PageInfo.of(list);
    }
}
